using System;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using ActiproSoftware.SyntaxEditor;
using ActiproSoftware.SyntaxEditor.Addons.Xml;
using ComponentFactory.Krypton.Docking;
using ComponentFactory.Krypton.Navigator;
using ComponentFactory.Krypton.Toolkit;
using DukeyCssFetch.api;

namespace DukeyCssFetch.UI
{
	// Token: 0x02000038 RID: 56
	public class ucEditor : UserControl
	{
		// Token: 0x06000241 RID: 577 RVA: 0x0001CAD8 File Offset: 0x0001ACD8
		public ucEditor()
		{
			
			this.InitializeComponent();
			MiddleModule.eventSend += new Send(this.method_1);
		}

		// Token: 0x06000244 RID: 580 RVA: 0x0001CB74 File Offset: 0x0001AD74
		public void AddFileToEditor(string path)
		{
			if (!File.Exists(path))
			{
				MessageBox.Show("该文件已经被移除!");
				return;
			}
			foreach (KryptonPage current in this.docknav.Pages)
			{
				if (string.Equals(current.Tag.ToString(), path))
				{
					this.docknav.SelectedPage = current;
					return;
				}
			}
			KryptonPage kryptonPage = new KryptonPage();
			FileInfo fileInfo = new FileInfo(path);
			string name = fileInfo.Name;
			kryptonPage.Text = name;
			kryptonPage.ToolTipTitle = path;
			kryptonPage.ToolTipBody = path;
			kryptonPage.Tag = path;
			XmlSyntaxLanguage language = new XmlSyntaxLanguage();
			SyntaxEditor syntaxEditor = new SyntaxEditor();
			syntaxEditor.Dock = DockStyle.Fill;
			syntaxEditor.Document.Language = language;
			syntaxEditor.Location = new Point(0, 0);
			syntaxEditor.CurrentLineHighlightingVisible = true;
			XmlSchemaResolver languageData = new XmlSchemaResolver();
			syntaxEditor.Document.LanguageData = languageData;
			syntaxEditor.Document.Outlining.Mode = OutliningMode.Automatic;
			syntaxEditor.LineNumberMarginVisible = true;
			syntaxEditor.WordWrap = WordWrapType.Word;
			kryptonPage.Controls.Add(syntaxEditor);
			ButtonSpecAny buttonSpecAny = new ButtonSpecAny();
			buttonSpecAny.Type = PaletteButtonSpecStyle.Close;
			buttonSpecAny.Click += new EventHandler(this.method_2);
			kryptonPage.ButtonSpecs.AddRange(new ButtonSpecAny[]
			{
				buttonSpecAny
			});
			this.docknav.Pages.AddRange(new KryptonPage[]
			{
				kryptonPage
			});
			this.docknav.SelectedPage = kryptonPage;
			DukeyEncode dukeyEncode = new DukeyEncode();
			Encoding encoding = dukeyEncode.GetEncoding(dukeyEncode.GetEncodingName(new FileInfo(path)));
			syntaxEditor.Document.LoadFile(path, encoding);
			syntaxEditor.Focus();
		}

		// Token: 0x06000246 RID: 582 RVA: 0x0001CD78 File Offset: 0x0001AF78
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.icontainer_0 != null)
			{
				this.icontainer_0.Dispose();
			}
			base.Dispose(disposing);
		}

		// Token: 0x06000247 RID: 583 RVA: 0x0001CD98 File Offset: 0x0001AF98
		private void InitializeComponent()
		{
			this.docknav = new KryptonDockableNavigator();
			((ISupportInitialize)this.docknav).BeginInit();
			this.docknav.SuspendLayout();
			base.SuspendLayout();
			this.docknav.Dock = DockStyle.Fill;
			this.docknav.Location = new Point(0, 0);
			this.docknav.Name = "docknav";
			this.docknav.Size = new Size(1000, 619);
			this.docknav.TabIndex = 1;
			this.docknav.Text = "kryptonDockableNavigator1";
			base.AutoScaleDimensions = new SizeF(6f, 12f);
			base.AutoScaleMode = AutoScaleMode.Font;
			base.Controls.Add(this.docknav);
			base.Name = "ucEditor";
			base.Size = new Size(1000, 619);
			((ISupportInitialize)this.docknav).EndInit();
			this.docknav.ResumeLayout(false);
			base.ResumeLayout(false);
		}

		// Token: 0x06000242 RID: 578 RVA: 0x0001CAFC File Offset: 0x0001ACFC
		private SyntaxEditor method_0()
		{
			if (this.docknav.Pages.Count == 0)
			{
				return null;
			}
			return this.docknav.SelectedPage.Controls[0] as SyntaxEditor;
		}

		// Token: 0x06000243 RID: 579 RVA: 0x0001CB30 File Offset: 0x0001AD30
		private void method_1(object object_0, object object_1)
		{
			FormInfo formInfo = object_1 as FormInfo;
			string frmname;
			if (formInfo != null && (frmname = formInfo.frmname) != null)
			{
				if (!(frmname == "addfile"))
				{
					return;
				}
				string path = formInfo.para.ToString();
				this.AddFileToEditor(path);
			}
		}

		// Token: 0x06000245 RID: 581 RVA: 0x0001CD48 File Offset: 0x0001AF48
		private void method_2(object sender, EventArgs e)
		{
			ButtonSpecAny buttonSpecAny = sender as ButtonSpecAny;
			this.docknav.Pages.Remove(buttonSpecAny.Owner as KryptonPage);
		}

		// Token: 0x0400026E RID: 622
		private KryptonDockableNavigator docknav;

		// Token: 0x0400026D RID: 621
		private IContainer icontainer_0;
	}
}
